package com.spgf.controller.fragments;

import java.util.Calendar;
import java.util.List;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.ListView;

import com.archtecture.model.exceptions.NegocioException;
import com.archtecture.model.patterns.PadraoFragmentMnt;
import com.spgf.controller.DespesaCadActivity;
import com.spgf.controller.R;
import com.spgf.model.entities.LancamentoModel;
import com.spgf.model.enums.Mes;
import com.spgf.model.rn.LancamentoRN;
import com.spgf.view.utils.AdapterListViewDespesas;
import com.spgf.view.utils.DialogManutencao;

public class PendenciasFragment extends PadraoFragmentMnt<LancamentoModel> implements OnItemLongClickListener {

	@Override
	public void atualizarLista() throws NegocioException {
		listview.setAdapter(new AdapterListViewDespesas(getActivity(), getListaModel()));
	}

	@Override
	public void configurarTela(LayoutInflater inflater, ViewGroup container) throws NegocioException {

		rootView = inflater.inflate(R.layout.activity_pendencias, container, false);

		listview = (ListView) rootView.findViewById(R.id.lst_resumo_categoria_pendentes);
		listview.setScrollbarFadingEnabled(true);
		listview.setOnItemLongClickListener(this);

		atualizarLista();
	}

	@Override
	protected void executarExcluir(Integer pCodigo) throws NegocioException {
		new LancamentoRN(getActivity()).excluir(pCodigo);
	}

	@Override
	protected boolean executarLongClick(AdapterView<?> pParent, View pView, int pPosition, long pID) throws NegocioException {

		if (pParent.getId() == R.id.lst_resumo_categoria_pendentes) {

			new DialogManutencao(this, getListaModel().get(pPosition)).show();
			return true;
		}

		return false;
	}

	@Override
	public Class<?> getControleCadastro() {
		return DespesaCadActivity.class;
	}

	@Override
	public List<LancamentoModel> getListaModel() throws NegocioException {

		Mes lMes = Mes.getEnum(Calendar.getInstance().get(Calendar.MONTH));
		return new LancamentoRN(rootView.getContext()).obterLancamentosPendentesAvaliacaoPorMes(lMes);
	}

}